package chap04;
public class StringDemo {
    public static void main(String [] args){
     String_api_1();
     String_api_2();
     System.out.println("第三段实验:");
     String_api_3();
     System.out.println("第四段实验:");
     String_aip_4();
     System.out.println("第五段实验:");
     String_api_5();
    }
    public static void String_api_1(){
        String s1="hello";
        String  s2="world";
        String s3="hello";
        System.out.println(s1==s3);
        s1=new String("hello");
        s2=new String ("hello");
        System.out.println(s1==s2);
        System.out.println(s1.equals(s2));
        char c[]={'s','u','m',' ','j','a','v','a'};
        String s4=new String(c);
        String s5=new String(c,4,4);
        System.out.println(s4);
        System.out.println(s5);
        //replace
    }
    public static void String_api_2(){
        String s1="sun java",s2="Sun java";
        System.out.println(s1.charAt(1));
        System.out.println(s2.length());
        System.out.println(s1.indexOf("java"));
        System.out.println(s2.indexOf("Java"));
        System.out.println(s1.equals(s2));
        System.out.println(s1.equalsIgnoreCase(s2));
    }
    public static void String_api_3(){
    String s="Welcome to Java World";
    String s1=" sun java";
    System.out.println(s.startsWith("Welcome"));
    System.out.println(s.endsWith("World"));
    String sL=s.toLowerCase();
    String sU=s.toUpperCase();
    System.out.println(sL);
    System.out.println(sU);
    String subS=s.substring(11);
    System.out.println(subS);
    String sp=s1.trim();
    }
    public static  void String_aip_4(){
        int j=12345;
        String sNumber=String.valueOf(j);
        System.out.println("j是" + sNumber.length() + "位数");
        String s="Mary,F,109";
        String[] sPlit=s.split(",");
        for(int i=0;i<sPlit.length;i++){
            System.out.println(sPlit[i]);
        }
    }
    public static void String_api_5(){
        StringBuffer buf=new StringBuffer("java");
        //在末尾添加
        buf.append("GG1");
        buf.append(3);
        int index=5;
        //插入
        buf.insert(index,"student");
        //设置
        char index2='G';
        buf.setCharAt(index2,'.');
        String s =buf.toString();
        System.out.println(s);
    }
}

